package com.springboot.cloud.web.handler;

import com.springboot.cloud.web.exception.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * <p> 异常切面拦截通知 </p>
 *
 * @author Bertram
 * @since 11/7/2019 2:34 PM
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private final Logger log = LoggerFactory.getLogger(getClass());

    /**
     * 自定义公共逻辑处理异常
     * @param e
     * @return
     */
    @ExceptionHandler(BusinessException.class)
    public ResponseEntity<String> handleCommonException(BusinessException e) {
        log.error(e.toString(),e);
        return ResponseEntity.status(e.getStatus()).body(e.getMessage());
    }
}
